package com.zs.hydrant.mapper;

import com.zs.hydrant.entity.User;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper // 标记为MyBatis映射接口
public interface UserMapper {
    // 根据手机号和角色查询用户（登录核心查询）
    User selectByPhoneAndRole(@Param("phone") String phone,@Param("role") Integer role);
    
    // 获取用户列表
    List<User> list();
    
    // 根据手机号更新用户角色
    int updateRoleByPhone(@Param("phone") String phone, @Param("role") Integer role);
    
    // 根据ID获取用户
    @Select("SELECT * FROM user WHERE id = #{id}")
    User getById(@Param("id") Integer id);
    
    // 根据ID删除用户
    @Delete("DELETE FROM user WHERE id = #{id}")
    int removeById(@Param("id") Integer id);
    
    // 更新用户信息
    @Update("UPDATE user SET username = #{username}, phone = #{phone}, password = #{password}, role = #{role}, status = #{status} WHERE id = #{id}")
    int updateById(User user);

    @Update("UPDATE user SET status = #{status} WHERE id = #{id}")
    int updateStatusById(User user);
}